<?php
require_once '../Model/Poster.php';

$function 	= $_POST['fct'];

switch($function) {
	case 'addPoster':
		$x			= $_POST['x'];
		$y			= $_POST['y'];
		$team		= $_POST['team'];
		$fileName	= $_POST['fileName'];
		addPoster($x, $y, $team, $fileName);
		break;
	case 'update':
		$timestamp	= null;
		if (null != $_POST['timestamp']) {
			$timestamp = $_POST['timestamp'];
			getPostersAfter($timestamp);
			
		}else {
			getAllPosters();
			
		}
	
}



function addPoster($x, $y, $team, $fileName) {
	$newPoster = Poster::newWithXYTeamAndFileName($x, $y, $team, $fileName);
	$newPoster->save();
	
}

function getPostersAfter($timestamp) {
	Poster::getPostersForJSonAfter($timestamp);
	
}

function getAllPosters() {
	Poster::allPostersForJSon();
	
}